/**
 * Created by linxiaofen on 2017/5/26.
 */
'use strict';
app.component('personalArticle',{
        templateUrl: './view/template/article.html',
        controller: function ($stateParams, $state, httpService, modalService) {
            var $ctrl = this;
            $ctrl.media = $stateParams.media;
            $ctrl.id = $stateParams.id;
            if($ctrl.id == 1){
                httpService.getArticleOne.query(function(data){
                    $ctrl.data = data;
                });
            }else if($ctrl.id == 2){
                httpService.getArticleTwo.query(function(data){
                    $ctrl.data = data;
                });
            }else{
                httpService.getArticleThree.query(function(data){
                    $ctrl.data = data;
                });
            }
            carouselInit();
            angular.element(document).ready(function () {
                scrollBarsCtrl();
            });
            function carouselInit(){
                $ctrl.myInterval = 2000;
                $ctrl.noWrapSlides = false;
                $ctrl.active = 0;
                var currIndex = 0;
                //modalService.showModal('暂时未开放此服务，正在开发中...')
                var slides = $ctrl.slides = [{
                    image: 'images/blog/blog-1.jpg',
                    title: 'First Thumbnail label',
                    text:'Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.',
                    id: currIndex++
                },{
                    image: 'images/blog/blog-2.jpg',
                    title: 'First Thumbnail label',
                    text:'Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.',
                    id: currIndex++
                },{
                    image: 'images/blog/blog-3.jpg',
                    title: 'First Thumbnail label',
                    text:'Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.',
                    id: currIndex++
                }];
                $ctrl.showMessage =function () {
                    modalService.showModal();
                };
                $ctrl.goNext = function(){
                    if($ctrl.id == 1){
                        $state.go('main.article',{id:"2",media:''});
                    }else if($ctrl.id == 2){
                        $state.go('main.article',{id:"3",media:'image'});
                    }else{
                    }
                };
            }

            $ctrl.return = function(){
                if($ctrl.id == 1){
                }else if($ctrl.id == 2){
                    $state.go('main.article',{id:"1",media:'carousel'});
                }else{
                    $state.go('main.article',{id:"2",media:''});
                }
            };
            function scrollBarsCtrl(){
                if (window.matchMedia("(max-width: 800px)").matches) {
                    $("#article").mCustomScrollbar("destroy");
                } else {
                    $("#article").mCustomScrollbar({
                        theme: "dark-2",
                        contentTouchScroll: true,
                        advanced: {
                            updateOnContentResize: true,
                            updateOnBrowserResize: true,
                            autoScrollOnFocus: false
                        }
                    });
                }
            }
        }
});